﻿Public Class Productos2 

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            
        End If
    End Sub

    Private Sub Productos2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.unidadescategoria' table. You can move, or remove it, as needed.
        Me.UnidadescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.unidadescategoria)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.productoscategoria' table. You can move, or remove it, as needed.
        Me.ProductoscategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.productoscategoria)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.tipoproducto' table. You can move, or remove it, as needed.
        Me.TipoproductoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipoproducto)

        Try
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.bodega' table. You can move, or remove it, as needed.
            Me.BodegaTableAdapter.Fill(Me.DbFireAndIceDataSet.bodega)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.unidadescategoria' table. You can move, or remove it, as needed.
            Me.UnidadescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.unidadescategoria)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.productos' table. You can move, or remove it, as needed.
            Me.ProductosTableAdapter.Fill(Me.DbFireAndIceDataSet.productos)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.productos' table. You can move, or remove it, as needed.
            Me.ProductosTableAdapter.Fill(Me.DbFireAndIceDataSet.productos)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.productos' table. You can move, or remove it, as needed.
            Me.ProductosTableAdapter.Fill(Me.DbFireAndIceDataSet.productos)
        Catch ex As Exception
            AlertControl1.Show(Owner, "ERROR", "No se pudo cargar los datos")
        End Try
        PanelArriba.Enabled = False
    End Sub

    Private Sub ProductosBindingNavigatorSaveItem_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.ProductosBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        ProductosBindingSource.AddNew()
        Mostrar()
        PanelArriba.Enabled = True
        PanelAbajo.Enabled = False
    End Sub


    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()
        PanelArriba.Enabled = True
        PanelAbajo.Enabled = False

    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                'ProductosTableAdapter.DeleteQuery(IdproductoTextEdit.EditValue)
                'Me.ProductoscategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.productoscategoria)
                AlertControl1.Show(Owner, "Productos", "Se eliminaron los datos")
                Me.ProductosTableAdapter.Fill(Me.DbFireAndIceDataSet.productos)
                Mostrar()
            Catch ex As Exception
                AlertControl1.Show(Owner, "ERROR", "Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas")
            End Try
        End If
        Mostrar()
    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
        ' •———————————————————————————————————————————————————————————————————————————————————————————————————————————————————•
        ' •——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————•
        ' | If DescripcionTextEdit.Text = "" Then                                                                                                                                |
        ' |     ErrorProvider1.SetError(DescripcionTextEdit, "Debe ingresar la descripción del Producto")                                                                        |
        ' | Else                                                                                                                                                                 |
        ' |                                                                                                                                                                      |
        ' |     If TextEdit1.Text = "" Then                                                                                                                                      |
        ' |         ErrorProvider1.SetError(TextEdit1, "Debe ingresar una categoria para Producto")                                                                              |
        ' |     Else                                                                                                                                                             |
        ' |         ErrorProvider1.SetError(DescripcionTextEdit, Nothing)                                                                                                        |
        ' |         ErrorProvider1.SetError(TextEdit1, Nothing)                                                                                                                  |
        ' |                                                                                                                                                                      |
        ' |                                                                                                                                                                      |
        ' |                                                                                                                                                                      |
        ' |         Try                                                                                                                                                          |
        ' |             Mostrar()                                                                                                                                                |
        ' |                                                                                                                                                                      |
        ' |         Catch ex As Exception                                                                                                                                        |
        ' |             ProductosTableAdapter.InsertQueryProductos(IdproductoTextEdit.EditValue, DescripcionTextEdit.EditValue, 1, "", 0, 1, 1, TextEdit1.EditValue, 0, 0)       |
        ' |             AlertControl1.Show(Owner, "ERROR", "No se pudo almacenar el Producto")                                                                                   |
        ' |         End Try                                                                                                                                                      |
        ' |         Mostrar()                                                                                                                                                    |
        ' |     End If                                                                                                                                                           |
        ' |         End If                                                                                                                                                       |
        ' |                                                                                                                                                                      |
        ' | ' •————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————• |





    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
       
        Mostrar()
        PanelAbajo.Enabled = True
        PanelArriba.Enabled = False



    End Sub

    
    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.ProductosBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub


    Private Sub GridControl1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
        Me.ProductosTableAdapter.Update(DbFireAndIceDataSet.productos)
    End Sub


    Private Sub GroupControl1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles GroupControl1.Paint

    End Sub

    Private Sub GridControl1_Validating_1(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles GridControl1.Validating
        Me.ProductosTableAdapter.Update(DbFireAndIceDataSet)
    End Sub
End Class